package com.cicadamob.contact.api.service;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Handler;

import com.cicadamob.contact.api.Utils.JsonParse;
import com.cicadamob.contact.api.Utils.NetWork.HttpUtil;
import com.cicadamob.contact.api.group.bean.ResultModel;
import com.cicadamob.contact.api.group.http.Http_Group_Util;

public class LoadUnInstall implements Runnable {

	private Context mContext;
	private Handler mHandler;
	private Map<String, String> userList;
	public LoadUnInstall(Context mContext, Handler mHandler,
			Map<String, String> userList){
		this.mContext=mContext;
		this.mHandler=mHandler;
		this.userList=userList;
		
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		loadInstall();
	}
	
	public boolean loadInstall(){

		// TODO Auto-generated method stub
		String xmlData=	Http_Group_Util.getClientInstallStatusXML(userList);
		Map<String, String> requestMap=new HashMap<String, String>();
		requestMap.put(HttpUtil.XML, xmlData);
		
		try {
			String result=ContactHttpClient.postZipXML(xmlData, ServerUrl.GET_CLIENT_INSTALL_STATUS);
			
			if(result!=null){
				ResultModel resultmodel = Http_Group_Util.parseResult(result);
				if(resultmodel.getRetcode()==0){
				//	ToastUtils.show(mContext, "网络不可用，请检测网络");
 				}else if(resultmodel.getRetcode()!=0){
//					ToastUtil.showToast(context, Http_Group_Util.getRetMsg(resultCode));
					return false;
				}
				String strinstalluser=resultmodel.getInstalluser();
				ArrayList<String> installList=new ArrayList<String>();
				if(strinstalluser!=null){
					installList=(ArrayList<String>) JsonParse.jsonTOPhoneList(strinstalluser);
				}
				
				APPContactDao.addInstallPhone(mContext, installList,userList);
				return true;
			}
			return false;
			
		} catch (SocketTimeoutException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	

}
